package com.ihr360.payroll.model.dto.reference;

import com.ihr360.alps.PropertyType;
import com.ihr360.commons.entityhandler.DateHandler;
import com.ihr360.commons.model.entity.NumberIdWithTime;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

/**
 * 引用实体的属性定义
 */
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Entity
@EntityListeners(DateHandler.class)
@Table(uniqueConstraints={@UniqueConstraint(columnNames={"refService_id","refId"}),@UniqueConstraint(columnNames={"refService_id","refName"})})
public class ReferenceProperty extends NumberIdWithTime<Long> {

    /**
     * 引用的属性
     */
    @Column(length = 40)
    private String refId;

    /**
     * 引用的属性显示名称
     */
    @Column(length = 40)
    private String refName;

    @Column(length = 40)
    @Enumerated(value = EnumType.STRING)
    private PropertyType type;

    @ManyToOne
    @JoinColumn
    private ReferenceService refService;


    public String getKey(){
        return this.refService.getRefId().concat(".").concat(this.refId);
    }

    public String getRefId() {
        return refId;
    }

    public void setRefId(String refId) {
        this.refId = refId;
    }

    public String getRefName() {
        return refName;
    }

    public void setRefName(String refName) {
        this.refName = refName;
    }

    public PropertyType getType() {
        return type;
    }

    public void setType(PropertyType type) {
        this.type = type;
    }

    public ReferenceService getRefService() {
        return refService;
    }

    public void setRefService(ReferenceService refService) {
        this.refService = refService;
    }
}